package Proxy.java;

/**
 * 深究Thread类的静态代理模式
 */
public class ThreadAgencyModel {

    public static void main(String[] args) {
        /*
        You you = new You();
        WedingCompany wedingCompany = new WedingCompany(you);
        wedingCompany.happyMarry();
        */

        //You you = new You();
        //new WedingCompany(you).happyMarry();

        new WedingCompany(new You()).happyMarry();

        //以上例子就是一个完整的代理模式
        //构造线程的第二种方法，本质上也是代理模式，请看：

//        ThreadARunnable threadARunnable = new ThreadARunnable();
//        new Thread(threadARunnable).start();

        //比较一下，会发现完全相同
        //需要注意的是，代理模式只要求能完成代理功能即可，不用把方法都放在相同的方法名中，所以Thread对象不用公共方法run没问题

    }

}

interface Marry{
    void happyMarry();
}

class You implements Marry{
    @Override
    public void happyMarry() {
        System.out.println("Mars got married");
    }
}

class WedingCompany implements Marry{

    Marry target;

    public WedingCompany(Marry target) {
        this.target = target;
    }

    @Override
    public void happyMarry() {
        before();
        target.happyMarry();
        after();
    }

    public void before(){
        System.out.println("筹办婚礼");
    }
    public void after(){
        System.out.println("收款");
    }
}
